	var rootPath = getRootPath();
	var showDateDom = $("#showDateaa");
	//初始化时间
	
	var now = new Date();
	var nowYear = now.getFullYear();
	var nowMonth = now.getMonth() + 1;
	var nowDate = now.getDate();
	console.log(showDateDom.attr('id'));
	showDateDom.attr('data-year', nowYear);
	showDateDom.attr('data-month', nowMonth);
	showDateDom.attr('data-date', nowDate);
$(document).ready(function(){
	
	//检测是否是会员
	$.ajax({
		headers: {'Cookie' : document.cookie },
		method : 'get',
		url : rootPath+'/customer/api/v1/queryUserOwner',
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			//alert("数据刷新失败");
		},
		success : function(resultData){ 
			if(resultData.length==0){
				alert("请先注册会员");
				window.location = rootPath + "/views/modules/register.html";
			}
			else{
				//轮播
				$.ajax({
				    type:"GET", 
				    url:rootPath+"/maintain/api/v1/getBindCarInfos", 
				    dataType:"json",      
				    async: false,
				    contentType:"application/json",               
				    data:null, 
				    success:function(data){ 
				    	if (data.length==0){
				    		alert("您还没有绑定车辆，请先绑定车辆。");
				    		to_bingCar();
				    	}
				        // 编辑轮播信息数据
						var wholeHtml = '';
						// 轮播（Carousel）指标
						var carousel_indicatorsHtml = '<ol class="carousel-indicators">';
						// 轮播（Carousel）项目
						var carousel_innerHtml = '<div class="carousel-inner">';
						var indexTemp= 0;
						$.each(data,function(carModelIndex,carModelObj){
							indexTemp = carModelIndex;
							if (0 == carModelIndex){
								
								carousel_indicatorsHtml += '<li class="active"><a href="#" class="active" onclick=setVin('+carModelIndex+')><img alt="" src="http://carowner.yonyouauto.com/fs01/carModel/BUICKakl.png"  data-target="#myCarInfos" data-slide-to="'+ carModelIndex +'" class="img-responsive"/ ></a><>';
							    carousel_innerHtml += "<div class='item active'>";
							    //品牌CODE赋值
							    $("#vin").val(carModelObj.vin);
							    $("#modelName").val(carModelObj.seriesName);
							} else {
								carousel_indicatorsHtml += '<li><a href="#" onclick=setVin('+carModelIndex+')><img alt="" src="http://carowner.yonyouauto.com/fs01/carModel/BUICKakl.png"  data-target="#myCarInfos" data-slide-to="'+carModelIndex+'" class="img-responsive"/ ></a><>';
								carousel_innerHtml += "<div class='item'>";
							}
							
							carousel_innerHtml += '<table><tr>';
							carousel_innerHtml +='<td width="70%"><img src="http://carowner.yonyouauto.com/fs01/carModel/BUICKakl.png"  width="100" height="60"></td>';
							carousel_innerHtml +="<td nowrap='nowrap' align='center' valign='middle'>";
							carousel_innerHtml += "<p>";
							carousel_innerHtml +="<span style='font: bolder;color: #000'>"+carModelObj.registNo+"</span><p>";
							carousel_innerHtml +="<span class='text-muted' style='color:#222'>"+carModelObj.seriesName+"</span>";
							carousel_innerHtml +="</td>"
							carousel_innerHtml +="</tr></table>";
							carousel_innerHtml +="<input type='hidden' id = 'vin_"+carModelIndex+"' value='"+carModelObj.vin+"' />";
							carousel_innerHtml +="<input type='hidden' id = 'modelName_"+carModelIndex+"' value='"+carModelObj.modelName+"' /></div>";
						});
						carousel_indicatorsHtml += "</ol> ";
						carousel_innerHtml += "</div>";
						$("#myCarInfos").append(carousel_indicatorsHtml);
						$("#myCarInfos").append(carousel_innerHtml);
						// 停止自动轮播
						$('#myCarInfos').carousel({
							interval: false
						})
						// 停止自动轮播
						$("#myCarInfos").carousel('pause');
						$('#myCarInfos').hammer().on('swipeleft', function(){
							$(this).carousel('next');
						});
						$('#myCarInfos').hammer().on('swiperight', function(){
							$(this).carousel('prev');
						});
				    	
				    },
				    error:function(data){
				    	//alert("数据刷新失败，请联系管理员！");
				    }
				 });
				//轮播结束
			}
		}
		
	})

  //保险公司信息取得
	$.ajax({
	    type:"GET", 
	    url:rootPath+"/leads/api/v1/InsuranceMap", 
	    dataType:"json",      
	    async: false,
	    contentType:"application/json",               
	    data:null, 
	    success:function(data){ 
	    	var wholeHtml = "";
			$.each(data,function(carModelIndex,InsuranceDto){
				var insuranceHtml = '';
				
				insuranceHtml = insuranceHtml + '<a  class="list-group-item"  style="text-align: left;padding-left: 100px;" onclick="sureCounselor('+carModelIndex+');">'+InsuranceDto.companyname
			                                   +'<input id="i'+carModelIndex+'" value="'+InsuranceDto.id+'" type="hidden">'
			                                   +'<input id="n'+carModelIndex+'" value="'+InsuranceDto.companyname+'" type="hidden">'
												+'</a>'
												
			    wholeHtml += insuranceHtml;
			});
			//wholeHtml += '<button type="button" class="btn btn-default" data-dismiss="modal" onclick="sureCounselor();">确定</button>'
			$("#insurancemap").append(wholeHtml);
	    },
	    error:function(data){
	    	//alert("数据刷新失败，请联系管理员！");
	    }
	 });
	//qiche信息取得
	$.ajax({
		headers: {'Cookie' : document.cookie },
		type:"GET", 
	    url:rootPath+"/maintain/api/v1/maintainSel", 
	    dataType:"json",      
	    async: false,
	    contentType:"application/json",               
	    data:null, 
	    success:function(data){ 
			$.each(data,function(carModelIndex,MaintainDto){
				$("#modelName").val(MaintainDto.seriesName);
				$("#licenseNo").val(MaintainDto.licenseNo);
				$("#vin").val(MaintainDto.vin);
				$("#engine").val(MaintainDto.engine);
				$("#saleDate").html(MaintainDto.billdate);
				$("#carid").val(MaintainDto.carid);
				$("#insurance").html(MaintainDto.insurance);
				$("#insurancestart").html(MaintainDto.insurancestart);
	    });
	    },
	    error:function(data){
	    	//alert("数据刷新失败，请联系管理员！");
	    }
	 });
	})
function selectInsurance(){
	$('#insuranceModal').modal({
		keyboard: false,
		backdrop:false
	});
}
function to_bingCar(){
	
	window.location = rootPath + "/views/homepage/Authentication.html";
}
function to_bingCar1(){
	
	window.location = "http://carowner.yonyouauto.com/wx/pub/personal?"+document.cookie;
}
function firm() {  
    //利用对话框返回的值 （true 或者 false）  
    if (confirm("是否取消绑定")) {  
    	alert("取消绑定成功！")
    	to_bingCar1();
    }  
    

}  
function updatecarinfo(){
	
	var ownercarrelationdto={"carid":$("#carid").val(),};
	$.ajax({ 
		headers: {'Cookie' : document.cookie },
        type:"POST", 
        url:rootPath+"/maintain/api/v1/updateCarinfoStu", 
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify(ownercarrelationdto), 
        success:function(data){ 
        	firm();
        	
        },
        error:function(data){
        	alert("取消绑定失败！");
        }
     });
}
function removeAllSpace(str) {
	return str.replace(/\s+/g, "");
	}

function sureCounselor(obj){
	$("#i"+obj).val;
	$("#id").val($("#i"+obj).val());
	$("#insurance").html($("#n"+obj).val());
	
	var carinfodto ={"insurer":$("#id").val(),"vin":$("#vin").val(),
	};
	$.ajax({ 
        type:"POST", 
        url:rootPath+"/leads/api/v1/updateCarinfo", 
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify(carinfodto), 
        success:function(data){ 
        	alert("修改成功！");
        },
        error:function(data){
        	alert("修改失败！");
        }
     });
	$("#insuranceBtn").click();
}

//车牌号修改
function surelicenseNo(obj){
	var nn=$("#licenseNo").val();
	var licenseNo=removeAllSpace(nn);
	var carinfodto ={"registNo":licenseNo,"vin":$("#vin").val(),
	};
	$.ajax({ 
        type:"POST", 
        url:rootPath+"/leads/api/v1/updateCarinfo", 
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify(carinfodto), 
        success:function(data){ 
        	alert("修改成功！");
        },
        error:function(data){
        	alert("修改失败！");
        }
     });

}

//选择养修预约时间，点击
var currentName = "";
function selectMaintainTime(current,obj){
	currentName = $(current).attr("name");
	 $("#isunDiv").hide();
	 $("#isunDiv").removeClass("active in");
	 $("#maintainDateSelDiv").show();
	 //初始化界面
	 $("#maintainDateSelDiv").addClass("active in");
	 
}



//数据初始化
function formatYear (nowYear) {
var arr = [];
for (var i = nowYear - 100; i <= nowYear; i++) {
   arr.push({
       id: i + '',
       value: i + '年'
   });
}
return arr;
}
function formatMonth () {
var arr = [];
var today = new Date();
for (var i = 1; i <= today.getMonth()+1; i++) {
   arr.push({
       id: i + '',
       value: i + '月'
   });
}
return arr;
}
function formatDate (count) {
var arr = [];
for (var i = 1; i <= count; i++) {
   arr.push({
       id: i + '',
       value: i + '日'
   });
}
return arr;
}
var yearData = function(callback) {
   callback(formatYear(nowYear))
}
var monthData = function (year, callback) {
   callback(formatMonth());
};
var dateData = function (year, month, callback) {
//setTimeout(function() {
	var today = new Date();
	var currentMonth = today.getMonth()+1;
	var currentDay = today.getDate();
	var days = currentMonth == month?currentDay:void(0);
   if (/^1|3|5|7|8|10|12$/.test(month)) {
       callback(formatDate(days||31));
   }
   else if (/^4|6|9|11$/.test(month)) {
       callback(formatDate(days||30));
   }
   else if (/^2$/.test(month)) {
       if (year % 4 === 0 && year % 100 !==0 || year % 400 === 0) {
           callback(formatDate(days||29));
       }
       else {
           callback(formatDate(days||28));
       }
   }
   else {
       throw new Error('month is illegal');
   }
};
function selectMaintainTime2(element){
	currentName = $(element).attr("name");
	var now = new Date();
	var nowYear = now.getFullYear();
	var nowMonth = now.getMonth() + 1;
	var nowDate = now.getDate();
	var $element = element.target;
	var oneLevelId = nowYear;
  var twoLevelId = nowMonth;
  var threeLevelId = nowDate;
	var iosSelect = new IosSelect(3, 
	        [yearData, monthData, dateData],
	        {
	            title: '时间选择',
	            itemHeight: 35,
	            relation: [1,1,0],
	            itemShowCount: 6,      
	            oneLevelId: oneLevelId,
	            twoLevelId: twoLevelId,
	            threeLevelId: threeLevelId,
	            showLoading: true,
	            callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
	            	if(selectTwoObj.id.length==1){
	            		selectTwoObj.id = "0"+selectTwoObj.id;
	            	}
	            	if(selectThreeObj.id.length==1){
	            		selectThreeObj.id = "0"+selectThreeObj.id;
	            	}
	            	var _name = $element.name;
	            	var _value = selectOneObj.id+"-"+selectTwoObj.id+"-"+selectThreeObj.id;
//	            	$("#birthdayVal").html(_value);
//	            	$("#birthday").val(_value);
	            	
	            	if(currentName == "bx"){
	            		
	            		$("#insurancestart").html(_value);
	            		var carinfodto ={"insuranceStartDate":_value,"vin":$("#vin").val()};
	            	}else if(currentName == "gc"){
	            	
	            		$("#saleDate").html(_value);
	            		$("#saleday").val($("#saleDate").html());
	            		var carinfodto ={"billDate":_value,"vin":$("#vin").val()};
	            	}
	            	
	            	$.ajax({ 
	                    type:"POST", 
	                    url:rootPath+"/leads/api/v1/updateCarinfo", 
	                    dataType:"json",      
	                    contentType:"application/json",               
	                    data:JSON.stringify(carinfodto), 
	                    success:function(data){ 
	                    	alert("修改成功！");
	                    },
	                    error:function(data){
	                    	alert("修改失败！");
	                    }
	                 });
	            	
	            }
	    });
}


//选择保养日期，时间之后确认
function confirmMaintainTime(obj) {
	$("#isunDiv").show();
	$("#isunDiv").addClass("active in");
	$("#maintainDateSelDiv").removeClass("active in");
	$("#maintainDateSelDiv").hide();
	if(currentName == "bx"){
		
		$("#insurancestart").html($("#day").html());
		$("#birthday").val($("#insurancestart").html());
		var carinfodto ={"insuranceStartDate":$("#insurancestart").html(),"vin":$("#vin").val()};
	}else if(currentName == "gc"){
	
		$("#saleDate").html($("#day").html());
		$("#saleday").val($("#saleDate").html());
		var carinfodto ={"billDate":$("#saleDate").html(),"vin":$("#vin").val()};
	}
	
	$.ajax({ 
        type:"POST", 
        url:rootPath+"/leads/api/v1/updateCarinfo", 
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify(carinfodto), 
        success:function(data){ 
        	alert("修改成功！");
        },
        error:function(data){
        	alert("修改失败！");
        }
     });
}
$("#mtDate").hide();
	$.ajax({
		method : 'get',
		url : rootPath+'/customer/api/v1/memberInfo',
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			//alert("数据刷新失败");
		},
		success : function(resultData){
			$.each(resultData,function(memberInfoIndex,memberInfoObj){
				if(resultData==null||resultData==""){
					$("#Imgurl").attr('src',memberInfoObj.headImgurl);
				}else{
					$("#Imgurl").attr('src',memberInfoObj.headImgurl);
					$("#userName").html(memberInfoObj.userName);
					$("#phone").html(memberInfoObj.phone);
					$("#userId").val(memberInfoObj.userId);
				}
				});
		}
	});